//import Vue from 'vue'
//import ElementUI from 'element-ui'
//import 'element-ui/lib/theme-default/index.css'
import App from './App'
import router from './router'
import store from './store'
import * as filters from './filters' // 全局filter
import './icons' // icon
import './errorLog'// error log
import './permission' // 权限
import '@/utils/buttonPermission.js'
import '@/utils/directives.js';
import {number} from  '@/utils/customOrder.js'         //全局自定义指令
// import MyInput from '@/views/Input/index.vue'          //全局input组件

import VueLazyload from 'vue-lazyload'

Vue.directive(
  "number",number
)
// Vue.component('MyInput', MyInput)



Vue.use(VueLazyload, {
  preLoad: 1.3,
  error: './../static/images/imgError.png',
  loading: './../static/images/loading.gif',
  attempt: 1
})
//import './mock'  // 该项目所有请求使用mockjs模拟
//import $ from 'jquery'

//修改element源码修改上传文件名
ELEMENT.Upload.components.Upload.methods.uploadFiles= function (files) {
  var _this = this;
  
  var postFiles = Array.prototype.slice.call(files);
  if (!this.multiple) {
    postFiles = postFiles.slice(0, 1);
  }

  if (postFiles.length === 0) {
    return;
  }

  postFiles.forEach(function (rawFile) {
    if(/(.jpg|.JPG|.gif|.GIF|.png|.PNG)$/.test(rawFile.name)){
      var aafile = new File([rawFile], Date.now()+rawFile.name ,{type: "text/plain"});
      _this.onStart(aafile);
      if (_this.autoUpload) _this.upload(aafile);
    }else{//(rawFile.name.indexOf(/pdf|word|txt/)>=0)
      _this.onStart(rawFile);
      if (_this.autoUpload) _this.upload(rawFile);
    }
  });
}

// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
});



Vue.config.productionTip = false
window.eventHub=new Vue({
  data () {
      return {
        // 定义数据
          val: ''
      }
  },
  created () {
      // 绑定监听
      this.$on('eventHub', (val)=>{
          this.val = val
      })
  }
});
window.VM= new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }

}); 

//给数组原型添加去掉空项的方法
Array.prototype.notempty = function(){
    return this.filter(t => t!=undefined && t!==null && t!="");
}

$(document).on('click','.el-tabs__item',function(){
  $('.viewer-container').appendTo('#tableBox .el-dialog');
})

import {closeUserSocket} from '@/store/modules/user.js'
import {closeHomeSocket} from '@/utils/webSocket.js' 
window.onbeforeunload = function () {
  if(!closeUserSocket()){
    closeHomeSocket()
  };
};


//给numer添加浮点数计算不精确的方法
function accMul(arg1) {
  var m = 0, s1 = arg1.toString()
  try {
      m += s1.split(".")[1].length;
  }
  catch (e) {
  }
  return Number(s1.replace(".", "")) * 10000 / Math.pow(10, m);
}

Number.prototype.mul = function (arg) {
  return accMul(arg, this);
};
